package com.citusdata.elven.util;


public class Stopwatch {
  private long    startTime = -1;
  private long    stopTime = -1;
  private boolean running = false;

  public synchronized void start() {
    startTime = System.currentTimeMillis();
    running = true;
  }

  public synchronized void stop() {
    stopTime = System.currentTimeMillis();
    running = false;
  }

  public synchronized long elapsedMilliseconds() {
    long elapsed;
    if (running) {
      elapsed = System.currentTimeMillis() - startTime;
    } else {
      elapsed = stopTime - startTime;
    }
    return elapsed;
  }

  public synchronized long elapsedSeconds() {
    long elapsed = elapsedMilliseconds();
    return (elapsed / 1000);
  }
}
